Live R Coding Session
Introducing the RStudio Layout
Basic layout
- Rstudio contains 4 panes: source, console, environment, and viewer
- The left pane is the source where you write code
- Try typing
2 + 2into the source panel and hitting ENTER- The console panel in the bottom-left will return a value of
4
- The console panel in the bottom-left will return a value of
- The top-right includes the Environment panel
- This contains information about any objects that you load into your environment
- Type
sum = 2 + 2into the source and hit ENTER - The object
sumshould appear in your environment
- The bottom-right includes the Viewer panel, where you will be able to see graphics that you generate
Reading Data into R
Index Variables
Additive Scale
Averaged Z-Scores
Interaction Terms
Differences across groups
Binary
Year I Year II Year III
327 277 221
0 1
327 221
| Bivariate | Multivariate | Interaction | |
|---|---|---|---|
| (Intercept) | -0.150*** (0.036) | -0.142** (0.051) | -0.184** (0.061) |
| moved | 0.234*** (0.045) | 0.273*** (0.055) | 0.334*** (0.073) |
| year | -0.046 (0.055) | 0.038 (0.086) | |
| moved × year | -0.142 (0.112) | ||
| Num.Obs. | 809 | 534 | 534 |
| R2 Adj. | 0.032 | 0.045 | 0.046 |
Continuous-ish
0 1 2
327 277 221
| Bivariate | Multivariate | Interaction | |
|---|---|---|---|
| (Intercept) | -0.150*** (0.036) | -0.121** (0.045) | -0.169** (0.056) |
| moved | 0.234*** (0.045) | 0.228*** (0.045) | 0.301*** (0.067) |
| year | -0.029 (0.027) | 0.019 (0.042) | |
| moved × year | -0.080 (0.054) | ||
| Num.Obs. | 809 | 809 | 809 |
| R2 Adj. | 0.032 | 0.032 | 0.033 |
More complex
0 1 2
327 277 221
| Bivariate | Multivariate | Interaction | |
|---|---|---|---|
| (Intercept) | -0.150*** (0.036) | -0.114* (0.046) | -0.184** (0.060) |
| moved | 0.234*** (0.045) | 0.232*** (0.045) | 0.334*** (0.072) |
| year2 | -0.060 (0.049) | 0.077 (0.092) | |
| year3 | -0.053 (0.054) | 0.038 (0.085) | |
| moved × year2 | -0.194+ (0.109) | ||
| moved × year3 | -0.142 (0.110) | ||
| Num.Obs. | 809 | 809 | 809 |
| R2 Adj. | 0.032 | 0.031 | 0.033 |
Differences over time
Cross-Sectional
| Bivariate | Multivariate | Interaction | |
|---|---|---|---|
| (Intercept) | -0.150*** (0.026) | -0.148*** (0.030) | -0.150*** (0.037) |
| moved | 0.232*** (0.032) | 0.232*** (0.032) | 0.234*** (0.046) |
| time | -0.004 (0.031) | -0.001 (0.052) | |
| moved × time | -0.004 (0.065) | ||
| Num.Obs. | 1634 | 1634 | 1634 |
| R2 Adj. | 0.030 | 0.030 | 0.029 |
Fixed Effects
| Simple | Fixed Effects | Interaction | |
|---|---|---|---|
| (Intercept) | 0.005 (0.022) | -0.330 (0.332) | -0.374 (0.333) |
| time | -0.005 (0.031) | -0.002 (0.023) | 0.000 (0.040) |
| moved | 0.044 (0.470) | ||
| moved × time | -0.004 (0.049) | ||
| Num.Obs. | 1634 | 1634 | 1634 |
| R2 Adj. | -0.001 | 0.442 | 0.442 |